import CardFreezonModule from './components/cardmodule/impl/CardFreezonModule.js'
import CardApplyingModule from './components/cardmodule/impl/CardApplyingModule.js'
import NotOpenModule from './components/cardmodule/impl/NotOpenModule.js'
import React from 'react'
import { CARDSTATE, CARDTYPE } from './model/CardInfoModel.js'
import CardOpenedModule from './components/cardmodule/impl/CardOpenedModule'
import StaffCardOpenedModule from './components/cardmodule/impl/StaffCardOpenModule'

/**
 * 根据卡实例和卡状态，初始化不同的卡面子类
 * @param item
 * @param index
 * @returns {*}
 */
export default function instanceCardModule (item, index) {
  let cardInstanceId = item.cardInstanceId
  switch (cardInstanceId) {
    case CARDTYPE.JHX_BUSCARD : {
      return instanceBusCardByState(item, index)
      break
    }
    case CARDTYPE.JHX_STAFFCARD : {
      return instanceStaffCardByState(item, index)
      break
    }
    default: {
      return null
    }
  }
}

function instanceBusCardByState (item, index) {
  let cardState = item.state
  switch (cardState) {
    case CARDSTATE.CARD_STATE_OPEN : {
      return <CardOpenedModule cardinfo={item} ref={'cardmodule' + index}/>
      break
    }
    case CARDSTATE.CARD_STATE_NOT_OPENED : {
      return <NotOpenModule/>
      break
    }
    case CARDSTATE.CARD_STATE_APPLYING : {
      return <CardApplyingModule/>
      break
    }
    case CARDSTATE.CARD_STATE_FREEZON: {
      return <CardFreezonModule/>
      break
    }
    default : {
      return null
    }
  }
}

function instanceStaffCardByState (item, index) {
  let cardState = item.state
  switch (cardState) {
    case CARDSTATE.CARD_STATE_OPEN : {
      return <StaffCardOpenedModule cardinfo={item} ref={'cardmodule' + index}/>
      break
    }
    default : {
      return null
    }
  }
}
